<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
		"http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>doh.robot CustomPlugin Test</title>

		<style>
			@import "../../../../util/doh/robot/robot.css";
		</style>

		<script type="text/javascript" src="../../../../dojo/dojo.js"></script>

		<script type="text/javascript">
			require([
				"doh/runner",
				"dojo/_base/array", "dojo/query", "dojo/robotx", "dijit/tests/helpers", "dojo/domReady!"
			], function(doh, array, query, robot, helpers){

				// TODO: convert this to non-robot test, clicking button using button.click()

				robot.initRobot('../test_CustomPlugin.html');

				var registry;
				doh.register("setup", [
					{
						name: "wait for editors to load",
						timeout: 5000,
						runTest: helpers.waitForLoad
					},
					function setVars(){
						registry = robot.window.require("dijit/registry");
					}
				]);

				var myPlugin;

				doh.register("isVisible", [
					function initialConditions(){
						var pluginIcon = query(".customIcon", robot.doc)[0];
						doh.t(helpers.isVisible(pluginIcon), "isVisible(pluginIcon)");
					}
				]);

					
				doh.register("testCustomPlugin", [
					{
						name: "toggleOn",
						setUp: function(){
							var editor = registry.byId("editor1");
							array.forEach(editor._plugins, function(plugin){
								if(plugin.name === "MyPlugin"){
									myPlugin = plugin;
								}
							});
						},
						timeout: 15000,
						runTest: function(){
							var d = new doh.Deferred();
							myPlugin.button.focus();
							robot.mouseMoveAt(myPlugin.button.domNode, 500);
							robot.mouseClick({left:true}, 500);
							
							robot.sequence(d.getTestCallback(function(){
								var foundClass = false;
								doh.t(myPlugin.button.get("checked"), "Verifying button was checked.");
								var sourceArea = myPlugin.sourceArea;
								doh.t(helpers.isVisible(sourceArea), "isVisible(sourceArea)");
							}), 1000);
							return d;
						}
					},
					{
						name: "toggleOff",
						setUp: function(){
							var editor = registry.byId("editor1");
							array.forEach(editor._plugins, function(plugin){
								if(plugin.name === "MyPlugin"){
									myPlugin = plugin;
								}
							});
						},
						timeout: 15000,
						runTest: function(){
							var d = new doh.Deferred();
							myPlugin.button.focus();
							robot.mouseMoveAt(myPlugin.button.domNode, 500);
							robot.mouseClick({left:true}, 500);
							robot.sequence(d.getTestCallback(function(){
								doh.f(myPlugin.button.get("checked"), "Verifying button was unchecked.");
								var sourceArea = myPlugin.sourceArea;
								doh.f(helpers.isVisible(sourceArea), "isVisible(sourceArea)");
							}), 1000);
							return d;
						}
					}
				]);
				doh.run();
			});
		</script>
	</head>
</html>
